package com.servlet.user;

import com.dao.UserDao;
import com.entity.User;
import com.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author admin
 */
@WebServlet(name = "UserSelectAllServlet",urlPatterns = "/UserSelectAllServlet.filter")
public class UserSelectAllServlet extends HttpServlet {
//    private String encoding;



    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("UserSelectAllServlet");
        SqlSession session = MybatisUtil.getSession();
        UserDao userDao = session.getMapper(UserDao.class);
        List<User> userList = userDao.selectUserList();
        request.setAttribute("userList",userList);
        request.getRequestDispatcher("/WEB-INF/page/user.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
